package com.syher.seconds.kill.kafka.core;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringBeanFactory implements ApplicationContextAware {
    private static ApplicationContext SPRING_CONTEXT;

    public static Object getBean(String name) {
        return SPRING_CONTEXT.getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        return SPRING_CONTEXT.getBean(clazz);
    }

    public static <T> T getBean(String name, Class<T> clazz) {
        return SPRING_CONTEXT.getBean(name, clazz);
    }

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        SPRING_CONTEXT = context;
    }
}
